{extend name="app/shop/view/base.html"/}
{block name="resources"}
{/block}
{block name="main"}

<div class="main-wrap">
	<div class="single-filter-box">
		<button type="button" class="layui-btn bg-color" onclick="add()">添加调拨单</button>
	</div>

	<!-- 搜索框 -->
	<div class="screen layui-collapse search-nav" lay-filter="selection_panel">
		<div class="layui-colla-item">
			<form class="layui-colla-content layui-form layui-show">
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">调拨单号：</label>
						<div class="layui-input-inline">
							<input type="text" name="allot_no" placeholder="请输入调拨单号" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">出库门店：</label>
						<div class="layui-input-inline">
							<select name="output_store_id"  lay-filter="store_list" class="len-mid">
								<option value="">全部</option>
								{foreach $store_list as $store_k => $store_v}
								<option value="{$store_v.store_id}">{$store_v.store_name}</option>
								{/foreach}
							</select>
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">入库门店：</label>
						<div class="layui-input-inline">
							<select name="input_store_id"  lay-filter="store_list" class="len-mid">
								<option value="">全部</option>
								{foreach $store_list as $store_k => $store_v}
								<option value="{$store_v.store_id}">{$store_v.store_name}</option>
								{/foreach}
							</select>
						</div>
					</div>
				</div>

				<div class="form-row">
					<button class="layui-btn bg-color" lay-submit lay-filter="search">筛选</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</form>
		</div>
	</div>

	<div class="layui-tab table-tab" lay-filter="doc_tab">
		<div class="layui-tab-content">
			<!-- 列表 -->
			<table id="doc_list" lay-filter="doc_list"></table>
		</div>
	</div>
</div>

<!-- 操作 -->
<script type="text/html" id="operation">
	<div class="table-btn">
		<a class="layui-btn" lay-event="detail">查看</a>
	</div>
</script>

{/block}
{block name="script"}
<script>
	var table, form, laytpl, element, layer_pass, repeat_flag = false; //防重复标识
	layui.use(['form', 'laytpl', 'element'], function() {
		form = layui.form;
		laytpl = layui.laytpl;
		element = layui.element;
		form.render();

		table = new Table({
			elem: '#doc_list',
			url: ns.url("stock://shop/stock/allocate"),
			cols: [
				[{
					field: 'allot_no',
					title: '调拨单号',
					width: '20%',
				}, {
					field: 'output_store_name',
					title: '出库门店',
					width: '15%',
				}, {
					field: 'input_store_name',
					title: '入库门店',
					width: '15%',
				}, {
					field: 'goods_money',
					title: '商品金额',
					width: '10%',
				}, {
					field: 'allot_time',
					title: '调拨时间',
					width: '20%',
					templet: function(data) {
						return ns.time_to_date(data.allot_time); //创建时间转换方法
					}
				}, {
					title: '操作',
					align: 'right',
					toolbar: '#operation',
				}]
			]
		});

		/**
		 * 监听工具栏操作
		 */
		table.tool(function(obj) {
			var data = obj.data;
			switch (obj.event) {
				case 'detail': //查看
					window.open(ns.url("stock://shop/stock/allotrecords?allot_id="+ data.allot_id));
					break;
			}
		});

		/**
		 * 搜索功能
		 */
		form.on('submit(search)', function(data){
			table.reload({
				page: {
					curr: 1
				},
				where: data.field
			});
			return false;
		});
		
	});

	function add() {
		location.href = ns.url("stock://shop/stock/addallocate");
	}
</script>
{/block}